package com.group525.cloudef.common;

import lombok.Getter;
import lombok.Setter;
/**
 * 结果数据s
 */

@Getter
@Setter
public class CommonResult<T> {

    private  long code;
    private  String msg;
    private  T data;

    protected CommonResult(long code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    protected CommonResult(long code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> CommonResult<T> success() {
        return new CommonResult<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg());
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
    }


    public static <T> CommonResult<T> success(String msg, T data) {
        return new CommonResult<>(ResultEnum.SUCCESS.getCode(), msg, data);
    }

    public static <T> CommonResult<T> success(String msg) {
        return new CommonResult<>(ResultEnum.SUCCESS.getCode(), msg);
    }

    public static <T> CommonResult<T> failed() {
        return new CommonResult<>(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMsg());
    }

    public static <T> CommonResult<T> failed(long code, String msg) {
        return new CommonResult<>(code, msg);
    }

    public static <T> CommonResult<T> failed(String msg) {
        return new CommonResult<>(ResultEnum.ERROR.getCode(), msg);
    }

}


